package com.ruoyi.blog.service.impl;

import com.ruoyi.blog.domain.BlogCategory;
import com.ruoyi.blog.mapper.BlogCategoryMapper;
import com.ruoyi.blog.service.IBlogCategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;
@Service
public class BlogCategoryServiceImpl implements IBlogCategoryService {
    @Resource
    private BlogCategoryMapper categoryMapper;

    public List<BlogCategory> getAllCategories() {
        return categoryMapper.getAllCategories();
    }

    public boolean deleteCategoryByIds(String ids) {
        String[] split = ids.split(",");
        int result = categoryMapper.deleteCategoryByIds(split);
        return result == split.length;
    }

    public int updateCategoryById(BlogCategory category) {
        return categoryMapper.updateCategoryById(category);
    }

    public int addCategory(BlogCategory category) {
        category.setDate(new Timestamp(System.currentTimeMillis()));
        return categoryMapper.addCategory(category);
    }
}
